<div><a href="javascript: loadUsers()">Load aa</a></div>
<div id="viewer_friends_div"></div>
<script type="text/javascript">
        /**
         * Fetch the Owner and Viewer with an opensocial dataRequest
         */
        function loadUsers() {
          var req = opensocial.newDataRequest();
          var opt_params = { };
        opt_params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [
          opensocial.Person.Field.PROFILE_URL
        ];
          req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER,opt_params), 'owner');
          req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER,opt_params), 'viewer');
          req.send(onLoadUsers);
        }

        /**
         * After the Owner is loaded, fetch their journal from the hi5 api server
         */
        function onLoadUsers(dataResponse) {
          var owner = dataResponse.get('owner').getData();
          var viewer = dataResponse.get('viewer').getData();
          var ownerId = owner.getField(opensocial.Person.Field.ID);
          sendNotification(viewer, owner);
        }


        function sendNotification(viewer, owner) {
          var toIds = new Array(1);
          toIds[0] = owner.getField(opensocial.Person.Field.ID);

          var notification = "<a href='" + viewer.getField(opensocial.Person.Field.PROFILE_URL) + "'>" + viewer.getDisplayName() + "</a> viewed your journal with the <a href='/friend/apps/displayAppCanvas.do?appId=192&userid=" + owner.getField(opensocial.Person.Field.ID) + "'>MyJournal</a> application";

          var opts = new Object();
          opts[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PRIVATE_MESSAGE;
	  opts[opensocial.Message.Field.TITLE] = "Faith Healer Calls In Faith Gastroenterologist"; 

          var message = opensocial.newMessage(notification, opts);
          document.getElementById('viewer_friends_div').innerHTML = message;
          opensocial.requestSendMessage(opensocial.DataRequest.PersonId.VIEWER, message);
        }
</script>

